package Smallprogram.dao.impl;

import Smallprogram.dao.BaseDao;
import Smallprogram.dao.BreakfastItemDao;
import Smallprogram.entiy.BreakfastItem;
import Smallprogram.entiy.Directory;

import javax.swing.text.html.parser.Entity;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class BreakfastItemDaoImpl extends BaseDao implements BreakfastItemDao {
    @Override
    public List<BreakfastItem> selectClasslist() {
        String sql = "SELECT * from Directory";
        ResultSet res = this.executeQuery(sql);
        List<BreakfastItem> list1 = new ArrayList<>();
        try {
            while (res.next()) {
                list1.add(new BreakfastItem(res.getInt(1), "", res.getInt(1),  res.getString(2), 0));
            }
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
        return list1;
    }

    @Override
    public List<BreakfastItem.Goods> selectSnacks() {
        String sql = "SELECT * FROM `BurgerKingDB`.`snacks`  ";
        ResultSet res = this.executeQuery(sql);
        List<BreakfastItem.Goods> list1 = new ArrayList<>();
        try {
            while (res.next()) {
//                boolean tien = false;
//                if (res.getInt(10) == 1) {
//                    tien = true;
//                }
                int ine = 65825;
//                List<String> listie = new ArrayList<>();
//                List<String> listid = new ArrayList<>();
//                List<String> listtup = new ArrayList<>();
////                List<String> lisidne = new ArrayList<>();
//                List<BreakfastItem.Goods.Entity> list = new ArrayList<>();
//                listtup.add("https://liualing.oss-cn-guangzhou.aliyuncs.com/" + res.getString(12) + res.getString(13));
                list1.add(new BreakfastItem.Goods(
                        res.getInt(1), res.getString("snacksName"), "https://liualing.oss-cn-guangzhou.aliyuncs.com/" + res.getString("Description") + res.getString("BevegPrice"),
                        res.getDouble("snacksPrice"),res.getString("snacksPtion"),res.getInt("Shelf")==1,res.getDouble("snacksYhPrice"),res.getInt("Directory")
                        )
                );
                ine++;
            }
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
        return list1;
    }

    @Override
    public List<BreakfastItem.Goods.Entity> selistliMnae() {
        String sql = "SELECT * FROM `snacks`";
        ResultSet res = this.executeQuery(sql);
        List<BreakfastItem.Goods.Entity> list = new ArrayList<>();

        try {
            while (res.next()) {
                List<String> spec_text = new ArrayList<>();
                List<String> spec = new ArrayList<>();
                list.add(new BreakfastItem.Goods.Entity("", res.getString(1), res.getString(9), 9999999.00, spec_text, spec, "https://liualing.oss-cn-guangzhou.aliyuncs.com/" + res.getString(9) + res.getString(10), 1, res.getDouble(4), res.getDouble(8)));
            }
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
        return list;
    }


    @Override
    public List<Directory> selectlist() {
        String sqlidiem = "SELECT * FROM Directory";
        ResultSet residiame = this.executeQuery(sqlidiem);
        List list = new ArrayList<>();
        try {
            while (residiame.next()) {
                list.add(new Directory(residiame.getInt(1), residiame.getString(2)));
            }
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
        return list;
    }

    @Override
    public int selectLien() {
        String sql = "SELECT COUNT(*) FROM `snacks`";
        ResultSet res = this.executeQuery(sql);
        int i = 0;
        try {
            if (res.next()) {
                i = res.getInt(1);
            }
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
        return i;
    }
}
